/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * quantSettings.java
 *
 * Created on 2-Nov-2010, 12:35:19 PM
 */
package balony;

/**
 *
 * @author Barry Young
 */
public class quantSettings extends javax.swing.JFrame {

    public final String MINPIXELS = "minPixels";
    public final String SNAP = "snap";
    public final String CIRC = "circ";
    public final String RETHRESH = "rethresh";
    Balony balony;

    /** Creates new form quantSettings */
    public quantSettings() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        quantgridCheckbox = new javax.swing.JCheckBox();
        quantPanel = new javax.swing.JPanel();
        circTextField = new javax.swing.JTextField();
        circLabel = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        minpixelsTextField = new javax.swing.JTextField();
        snapTextField = new javax.swing.JTextField();
        snapLabel = new javax.swing.JLabel();
        sizePopupJCheckBox = new javax.swing.JCheckBox();
        automationJPanel = new javax.swing.JPanel();
        reThreshJCheckBox = new javax.swing.JCheckBox();
        jLabel1 = new javax.swing.JLabel();
        allowBadSpotsJTextField = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        autoRotateJCheckBox = new javax.swing.JCheckBox();
        jLabel4 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();

        quantgridCheckbox.setText("Grid");
        quantgridCheckbox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                quantgridCheckboxActionPerformed(evt);
            }
        });

        setTitle("Imaging Parameters");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
            public void windowDeactivated(java.awt.event.WindowEvent evt) {
                formWindowDeactivated(evt);
            }
        });

        quantPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Quantification settings"));

        circTextField.setText("0.8");
        circTextField.setToolTipText("The minimum circularity value required for a spot to be recognized (0.0-1.0)");
        circTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                circTextFieldActionPerformed(evt);
            }
        });

        circLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        circLabel.setText("Circ:");

        jLabel2.setText("Min pixels:");

        minpixelsTextField.setText("8");
        minpixelsTextField.setToolTipText("The minimum number of pixels that defines a spot in the array.");
        minpixelsTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                minpixelsTextFieldActionPerformed(evt);
            }
        });

        snapTextField.setText("0.25");
        snapTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                snapTextFieldActionPerformed(evt);
            }
        });

        snapLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        snapLabel.setText("Snap:");
        snapLabel.setToolTipText("How far spots can deviate from the grid pattern before being discarded");

        sizePopupJCheckBox.setText("Show colony size pop-up after quantification");

        javax.swing.GroupLayout quantPanelLayout = new javax.swing.GroupLayout(quantPanel);
        quantPanel.setLayout(quantPanelLayout);
        quantPanelLayout.setHorizontalGroup(
            quantPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(quantPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(quantPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(quantPanelLayout.createSequentialGroup()
                        .addGroup(quantPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(quantPanelLayout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(minpixelsTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(quantPanelLayout.createSequentialGroup()
                                .addComponent(circLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(circTextField)))
                        .addGap(18, 18, 18)
                        .addComponent(snapLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(snapTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(sizePopupJCheckBox))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        quantPanelLayout.setVerticalGroup(
            quantPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, quantPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(quantPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(quantPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(minpixelsTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel2))
                    .addGroup(quantPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(snapTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(snapLabel)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(quantPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(circTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(circLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(sizePopupJCheckBox)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        automationJPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Automation"));

        reThreshJCheckBox.setSelected(true);
        reThreshJCheckBox.setText("Automatically re-threshold images with bad spots.");

        jLabel1.setText("Allow up to");

        allowBadSpotsJTextField.setText("8");

        jLabel3.setText("bad spots.");

        autoRotateJCheckBox.setSelected(true);
        autoRotateJCheckBox.setText("Rotate image on failed auto-grid.");
        autoRotateJCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                autoRotateJCheckBoxActionPerformed(evt);
            }
        });

        jLabel4.setText("When analyzing multiple files, abandon auto-grid after");

        jTextField1.setText("120");

        jLabel5.setText("seconds of trying.");

        javax.swing.GroupLayout automationJPanelLayout = new javax.swing.GroupLayout(automationJPanel);
        automationJPanel.setLayout(automationJPanelLayout);
        automationJPanelLayout.setHorizontalGroup(
            automationJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(automationJPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(automationJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(automationJPanelLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(allowBadSpotsJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel3))
                    .addComponent(reThreshJCheckBox)
                    .addComponent(autoRotateJCheckBox)
                    .addComponent(jLabel4)
                    .addGroup(automationJPanelLayout.createSequentialGroup()
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel5)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        automationJPanelLayout.setVerticalGroup(
            automationJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(automationJPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(reThreshJCheckBox)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(automationJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(allowBadSpotsJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(autoRotateJCheckBox)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(automationJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addContainerGap(24, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(automationJPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(quantPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(quantPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(automationJPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void circTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_circTextFieldActionPerformed
}//GEN-LAST:event_circTextFieldActionPerformed

    private void minpixelsTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_minpixelsTextFieldActionPerformed
}//GEN-LAST:event_minpixelsTextFieldActionPerformed

    private void snapTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_snapTextFieldActionPerformed
}//GEN-LAST:event_snapTextFieldActionPerformed

    private void quantgridCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quantgridCheckboxActionPerformed
}//GEN-LAST:event_quantgridCheckboxActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        System.out.println("Window closing");
        balony.prefs.setProperty(MINPIXELS, minpixelsTextField.getText());
        balony.prefs.setProperty(SNAP, snapTextField.getText());
        balony.prefs.setProperty(CIRC, circTextField.getText());
        balony.prefs.setProperty(RETHRESH, reThreshJCheckBox.isSelected() ? "TRUE" : "FALSE");
        balony.savePrefs();
    }//GEN-LAST:event_formWindowClosed

    private void formWindowDeactivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowDeactivated
                System.out.println("Window closing");
        balony.prefs.setProperty(MINPIXELS, minpixelsTextField.getText());
        balony.prefs.setProperty(SNAP, snapTextField.getText());
        balony.prefs.setProperty(CIRC, circTextField.getText());
        balony.prefs.setProperty(RETHRESH, reThreshJCheckBox.isSelected() ? "TRUE" : "FALSE");
        balony.savePrefs();
    }//GEN-LAST:event_formWindowDeactivated

    private void autoRotateJCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_autoRotateJCheckBoxActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_autoRotateJCheckBoxActionPerformed

    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//
//            public void run() {
//                new quantSettings().setVisible(true);
//            }
//        });
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JTextField allowBadSpotsJTextField;
    public javax.swing.JCheckBox autoRotateJCheckBox;
    private javax.swing.JPanel automationJPanel;
    private javax.swing.JLabel circLabel;
    public javax.swing.JTextField circTextField;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JTextField jTextField1;
    public javax.swing.JTextField minpixelsTextField;
    private javax.swing.JPanel quantPanel;
    public javax.swing.JCheckBox quantgridCheckbox;
    public javax.swing.JCheckBox reThreshJCheckBox;
    public javax.swing.JCheckBox sizePopupJCheckBox;
    private javax.swing.JLabel snapLabel;
    public javax.swing.JTextField snapTextField;
    // End of variables declaration//GEN-END:variables
}
